/*
 * seqFeederV.cpp
 *
 *  Created on: 2011-09-03
 *      Author: pawel
 */
#include"seqFeederV.h"
#include<memory>
#include <stdexcept>
seqFeeder::seqFeeder()
:mutex(NULL),notFull(NULL),notEmpty(NULL),full(false),empty(false),closed(false),productionEnded(false)
{
	try{
		std::auto_ptr<pthread_mutex_t> smartMutex(new pthread_mutex_t);
		std::auto_ptr<pthread_cond_t> smartNotFull(new pthread_cond_t);
		std::auto_ptr<pthread_cond_t> smartNotEmpty(new pthread_cond_t);
		pthread_mutex_init(smartMutex.get(),NULL);
		pthread_cond_init(smartNotFull.get(),NULL);
		pthread_cond_init(smartNotEmpty.get(),NULL);

		mutex = smartMutex.release();
		notFull = smartNotFull.release();
		notEmpty = smartNotEmpty.release();

	}catch(std::exception& e){
		throw;
	}
}
seqFeeder::~seqFeeder(){
	if(mutex != NULL){
		pthread_mutex_destroy(mutex);
		delete mutex;

	}
	if(notFull != NULL){
		pthread_cond_destroy(notFull);
		delete notFull;
	}
	if(notEmpty != NULL){
		pthread_cond_destroy(notEmpty);
		delete notEmpty;
	}

}
bool seqFeeder::isFull()const{return full;}
bool seqFeeder::isEmpty()const{return empty;}
bool seqFeeder::isClosed()const{return closed;}
bool seqFeeder::isProductionEnded()const{return productionEnded;}
void seqFeeder::setClose(){closed = true; }
void seqFeeder::endProduction(){productionEnded = true ;}
pthread_mutex_t* seqFeeder::getMutex()const{ return mutex;}
pthread_cond_t*  seqFeeder::getNotFull()const{return notFull;}
pthread_cond_t*  seqFeeder::getNotEmpty()const{return notEmpty;}
